package com.muyuan.clues.strategy.impl;

import com.muyuan.clues.domain.TbAssignRecord;
import com.muyuan.clues.domain.TbClue;
import com.muyuan.clues.mapper.SysDictDataMapper;
import com.muyuan.clues.mapper.SysUserMapper;
import com.muyuan.clues.mapper.TbAssignRecordMapper;
import com.muyuan.clues.strategy.Rule;
import com.muyuan.common.core.domain.entity.SysDictData;
import com.muyuan.common.core.domain.entity.SysUser;
import com.muyuan.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;



/**
 * 使用规则的方式进行线索的自动分配
 * 规则：
 * 1.将想要学健身的分配给zhangsan1
 * 2.将想要学瑜伽的分配给zhangsan2
 * 3.将想要学瑜伽的分配给zhangsan3
 * 4.不满足规则的不进行分配，由管理员或主管来进行分配
 */
@ConditionalOnProperty(name = "rule.clue.import", havingValue = "rule")
@Service("ClueRuleStrategy")
public class RuleStrategy implements Rule {

    @Autowired
    private TbAssignRecordMapper assignRecordMapper;
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private SysDictDataMapper dictDataMapper;
    private static SysUser zhangsan1 = new SysUser();
    private static SysUser zhangsan2 = new SysUser();
    private static SysUser zhangsan3 = new SysUser();
    //内存中健身的内容--提前预加载在内存中
    private static SysDictData subject1 = new SysDictData();
    //内存中瑜伽的内容--提前预加载在内存中
    private static SysDictData subject2 = new SysDictData();
    //内存中舞蹈的内容--提前预加载在内存中
    private static SysDictData subject3 = new SysDictData();


    @PostConstruct
    public void init() {
        //空间换时间的方式将数据库中的科目读取到内存中
        //预加载学科数据到内存中
        List<SysDictData> course_subject = dictDataMapper.selectDictDataByType("course_subject");
        for (SysDictData index: course_subject) {
            if(index.getDictLabel().equals("健身")){
                subject1 = index;
            }
            if(index.getDictLabel().equals("瑜伽")){
                subject2 = index;
            }
            if(index.getDictLabel().equals("舞蹈")){
                subject3 = index;
            }
        }
        //预加载zhangsan1和zhangsan2的数据到内存中
        zhangsan1 = userMapper.selectUserByName("zhangsan1");
        zhangsan2 = userMapper.selectUserByName("zhangsan2");
        zhangsan3 = userMapper.selectUserByName("zhangsan3");
    }

    /**========利用空间换时间将部分的数据提前存放到内存中======================**/
    @Override
    public Boolean loadRule(TbClue clue) {
        //TODO 完成基于规则分配线索部分的代码
        /**
         * 使用规则的方式进行线索的自动分配
         * 规则：
         * 1.将想要学健身的分配给zhangsan1
         * 2.将想要学瑜伽的分配给zhangsan2
         * 3.将想要学瑜伽的分配给zhangsan3
         * 4.不满足规则的不进行分配，由管理员或主管来进行分配
         */
        return null;
    }



}